package com.we.netty;

import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;

public class MyWatcher implements Watcher {
    @Override
    public void process(WatchedEvent watchedEvent) {
        //判断事件类型
        Event.EventType type = watchedEvent.getType();
        if (type == Event.EventType.None){
            if(watchedEvent.getState() == Event.KeeperState.SyncConnected){
                System.out.println("zookeeper连接成功！");
            }else if(watchedEvent.getState() == Event.KeeperState.AuthFailed){
                System.out.println("zookeeper认证失败！");
            }else if(watchedEvent.getState() == Event.KeeperState.Disconnected){
                System.out.println("zookeeper断开连接！");
            }
        }else if(type == Event.EventType.NodeCreated){
            System.out.println("创建节点成功！");
        }else if(type == Event.EventType.NodeChildrenChanged) {
            System.out.println("孩子节点修改！");
        }else if(type == Event.EventType.NodeDeleted){
            System.out.println("节点删除成功！");
        }
    }
}
